<?php
class CompanyAccount extends AppModel {
	var $name = 'CompanyAccount';
	var $useTable = 'company_account_mst';
	
	var $primaryKey = 'id';
	var $displayField = 'login_id';
	
	var $belongsTo = array('Company' =>  
                            array('className'  => 'Company', 
                                  'conditions' => "\"Company\".deleted is null",  
                                  'order'      => '',  
                                  'foreignKey' => 'company_id'  
                            )    
                      );

	function Login_Valid($Valid,$params){
		$message = '';
		$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_id','required');		
		$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_pwd','required');		
		return $message;
	}
	
	function Email_Valid($Valid,$params){
		$message = '';
		$message .= $Valid->ErrorMsg($params,'Company/email','required');
		$message .= $Valid->ErrorMsg($params,'Company/email','email');
		$message .= $Valid->ErrorMsg($params,'Company/email','confirm');
		
		
		return $message;
	}	
	
	function Pwd_Valid($Valid,$params){	
		$message = '';
		$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_pwd','required');
		$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_pwd','confirm');
		$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_pwd','minmaxlength','6-20');	
		
		return $message;
	}

	
	function Pwd_Email_Valid($Valid,$params){
		$message = '';
		$message .= $Valid->ErrorMsg($params,'Company/account_email','required');
		$message .= $Valid->ErrorMsg($params,'Company/account_email','email');
		return $message;
	}
	
	function Reg_Valid($Valid,$params){
		$message = '';
		$message .= $Valid->ErrorMsg($params,'Company/company_name','required');	
		$message .= $Valid->ErrorMsg($params,'Company/company_name','mbmaxlength','300');
		$message .= $Valid->ErrorMsg($params,'Company/company_alias','mbmaxlength','300');		
		$message .= $Valid->ErrorMsg($params,'Company/company_created_year','required');
//		$message .= $Valid->ErrorMsg($params,'Company/company_created_month','required');
		$message .= $Valid->ErrorMsg($params,'Company/deputy_name','required');	
		$message .= $Valid->ErrorMsg($params,'Company/deputy_name','mbmaxlength','300');
		$message .= $Valid->ErrorMsg($params,'Company/employee_count','required');	
		$message .= $Valid->ErrorMsg($params,'Company/employee_count','maxlength','300');	
		$message .= $Valid->ErrorMsg($params,'Company/introduce','required');	
		$message .= $Valid->ErrorMsg($params,'Company/introduce','mbmaxlength','2000');
		$message .= $Valid->ErrorMsg($params,'Company/address','required');		
		$message .= $Valid->ErrorMsg($params,'Company/address','mbmaxlength','2000');	
		$message .= $Valid->ErrorMsg($params,'Company/tel1','required');	
        $message .= $Valid->ErrorMsg($params,'Company/tel1','maxlength','300');
		$message .= $Valid->ErrorMsg($params,'Company/tel2','maxlength','300');
		$message .= $Valid->ErrorMsg($params,'Company/email','required');
		$message .= $Valid->ErrorMsg($params,'Company/email','mbmaxlength',100);		
		$message .= $Valid->ErrorMsg($params,'Company/email','confirm'); 
		$message .= $Valid->ErrorMsg($params,'Company/email','email');
		$message .= $Valid->ErrorMsg($params,'Company/email_confirm','required');
		$message .= $Valid->ErrorMsg($params,'Company/incept_email','confirm');
		$message .= $Valid->ErrorMsg($params,'Company/incept_email','email');
		$message .= $Valid->ErrorMsg($params,'Company/incept_email','mbmaxlength',100);
		$message .= $Valid->ErrorMsg($params,'Company/url','url'); 
		$message .= $Valid->ErrorMsg($params,'Company/url','mbmaxlength',100); 				
		$message .= $Valid->ErrorMsg($params,'CompanyAccount/name','required');					

		$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_id','required'); 
		$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_id','minmaxlength','6-20');
		$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_id', 'htmlspecialchars');
		$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_pwd','required'); 
		$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_pwd','confirm'); 
		//wang.wei 2012/4/12 edit start
		//$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_pwd','minmaxlength','6-20');
		$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_pwd','minmaxlength','8-20');
		$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_pwd', 'password_input_company');
		//wang.wei 2012/4/12 edit end
		$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_pwd', 'htmlspecialchars');
		
		$message .= $Valid->ErrorMsg($params,'Company/pwd_remain_id','required');	
		$message .= $Valid->ErrorMsg($params,'Company/pwd_remain_answer','required');	
		$message .= $Valid->ErrorMsg($params,'Company/pwd_remain_answer','mbminmaxlength','1-20'); 
		$message .= $Valid->ErrorMsg($params,'Company/pwd_remain_answer', 'htmlspecialchars');

		
				
		return $message;
	}
	
    function doDelete($id){
		$sql="update company_account_mst set deleted=now() where id in ($id)";
		$p=$this->query($sql);
	}
	
	function updateMissTime($id, $val = null) {
		$sql="UPDATE company_account_mst SET last_miss_login_time='$val' WHERE id = $id";
		$p=$this->query($sql);
	}
}
?>